# main.py
from fastapi import FastAPI, Depends
from .database import mysql_db, sqlserver_db, sqlite_db
from .mysql_crud import get_mysql_users, create_mysql_user
from .sqlserver_crud import get_sqlserver_orders
from .sqlite_crud import get_sqlite_items

app = FastAPI()

# 启动时连接数据库
@app.on_event("startup")
async def startup():
    await mysql_db.connect()
    await sqlserver_db.connect()
    await sqlite_db.connect()

# 关闭时断开连接
@app.on_event("shutdown")
async def shutdown():
    await mysql_db.disconnect()
    await sqlserver_db.disconnect()
    await sqlite_db.disconnect()

# MySQL 路由示例
@app.get("/mysql/users/")
async def read_mysql_users():
    return await get_mysql_users()

@app.post("/mysql/users/")
async def create_mysql_user_route(name: str):
    return await create_mysql_user(name)

# 其他数据库路由类似...